package com.next.common;

import com.next.exception.BusinessException;
import com.next.exception.ParamException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.json.Json;

@ControllerAdvice
public class GlableExceptionHandler {

//    @ExceptionHandler(value = RuntimeException.class)
//    @ResponseBody
//    public JsonData exceptionHandler(Exception ex) {
//        if (ex instanceof ParamException || ex instanceof BusinessException) {
//            return JsonData.fail(ex.getMessage());
//        }
//        System.out.println(ex.getMessage());
//        return JsonData.fail(ex.getMessage());
//    }

    @ExceptionHandler(value = Error.class)
    @ResponseBody
    public JsonData errorHandler(Exception ex) {

        return JsonData.fail("系统异常, 请联系管理员!");
    }
}
